package com.kaciula.letsdoit.ui;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.widget.Toast;

import java.util.ArrayList;

public class WastesOverlay extends ItemizedOverlay<OverlayItem> {
    
    private ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
    
    private Drawable marker = null;
    
    private Context mCtx;
    
    public WastesOverlay(Drawable marker) {
        super(marker);
        this.marker = marker;
    }
    
    public WastesOverlay(Drawable marker, Context ctx) {
        super(marker);
        mCtx = ctx;
        this.marker = marker;
    }
    
    public void addOverlay(OverlayItem overlay) {
        items.add(overlay);
        populate();
    }

    @Override
    protected OverlayItem createItem(int i) {
        return items.get(i);
    }

    @Override
    public int size() {
        return items.size();
    }

    @Override
    public boolean onTap(int index) {
        OverlayItem item = items.get(index);
        Toast.makeText(mCtx, item.getTitle(), Toast.LENGTH_SHORT).show();
        return true;
    }

    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        super.draw(canvas, mapView, shadow);
        boundCenterBottom(marker);
    }
}
